﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Yang.DataBase;

public partial class updateDataSet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "text/plain";
        Response.Charset = "utf-8";
        string strJson = "";


        string ProductType = "";                //成果类型
        string strQueryString = "";

        ProductType = Request.QueryString[0].ToString();
        string tableName = Utility.ProductId2Name(ProductType);

        strQueryString = Request.QueryString[1].ToString();
        strQueryString = strQueryString.Substring(0, strQueryString.Length - 1);

        string[] strValuePairs = strQueryString.Split('=');
        string columnNames = strValuePairs[0];
        string columnValues = strValuePairs[1];

        int nColumns = columnNames.Split(';').Length;

        string[] columnNamesArray = columnNames.Split(';');
        string[] columnValuesArray = columnValues.Split(';');

        string[] paramArray = new string[nColumns];
        string paramList = "";
        for (int i = 1; i < nColumns; i++)
        {
            //paramArray[i] = "@" + i.ToString();
            paramList += columnNamesArray[i] + " = '" + columnValuesArray[i] + "',";
        }
        paramList = paramList.Remove(paramList.Length - 1, 1);

        string strWhere = " where 编号 = " + columnValuesArray[0] + "";

        string strSql = "update " + tableName + " set " + paramList + strWhere;
        try
        {
            //SqlParameter[] m_sqlParam = new SqlParameter[nColumns];
            //for (int i = 0; i < nColumns; i++)
            //{
            //    m_sqlParam[i] = new SqlParameter(paramArray[i], columnValuesArray[i]);
            //}
            Database.ExecuteSql(strSql);

            strJson = "{\"result\":\"OK\"}";
        }
        catch (Exception ex)
        {
            Log.WriteException(DateTime.Now.ToString() + ";" + ex.Message);
            strJson = "{\"result\":\"ERROR\"}";
        }

        Response.Write(strJson);
    }
}
